const axios = require('axios');
const FormData = require('form-data');
const { 获取输入_plus } = require('lidong-utils-zh');

// 老师签到 teacherSign 学员签到 10
const getCourseOffersQrCode = async ({ ssoToken, id, signType }) => {

    let data = new FormData();
    data.append('id', id);
    data.append('signType', signType);
    data.append('', '');

    let config = {
        method: 'POST',
        url: 'https://pxjg-gd.i-aq.cn/pxjgApi/train/trainRecord/genQrcode',
        headers: {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
            'Accept': 'application/json, text/plain, */*',
            'Accept-Encoding': 'gzip, deflate, br, zstd',
            'Pragma': 'no-cache',
            'Cache-Control': 'no-cache',
            'sec-ch-ua-platform': '"Windows"',
            'sec-ch-ua': '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"',
            'sso-token': ssoToken,
            'project-code': 'gdpxjg',
            'sec-ch-ua-mobile': '?0',
            'token-version': 'V2.1',
            'product-code': 'pxjgYwpt',
            'Origin': 'https://pxjg-gd.i-aq.cn',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'Cookie': 'pageNo=1; pageSize=10'
        },
        data: data
    };

    const result = (await axios.request(config)).data

    return result
}

const getTrainList = async ({
    ssoToken
}) => {

    let data = new FormData();
    data.append('selKeyWord', '');
    data.append('teacherUserName', '');
    data.append('pageNo', '1');
    data.append('pageSize', '10');
    data.append('areaCode', '');
    data.append('trainStatus', '');
    data.append('courseType', '');
    data.append('subjectCodeQuery', '');
    data.append('selQueryFlag', 'list1');

    let config = {
        method: 'POST',
        url: 'https://pxjg-gd.i-aq.cn/pxjgApi/train/trainRecord/listData',
        headers: {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
            'Accept': 'application/json, text/plain, */*',
            'Accept-Encoding': 'gzip, deflate, br, zstd',
            'sec-ch-ua-platform': '"Windows"',
            'sec-ch-ua': '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"',
            'sso-token': ssoToken,
            'project-code': 'gdpxjg',
            'sec-ch-ua-mobile': '?0',
            'token-version': 'V2.1',
            'product-code': 'pxjgYwpt',
            'Origin': 'https://pxjg-gd.i-aq.cn',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://pxjg-gd.i-aq.cn/pxjgYwpt/train/trainRecord?pageTitle=%E7%BA%BF%E4%B8%8B%E6%8E%88%E8%AF%BE',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'Cookie': 'pageNo=1; pageSize=10'
        },
        data: data
    };

    const result = (await axios.request(config)).data

    return result

}


// 获取学员签到二维码
const getTrainRecord = async ({
    ssoToken,
    id
}) => {

    let data = new FormData();
    data.append('id', id);

    let config = {
        method: 'POST',
        url: 'https://pxjg-gd.i-aq.cn/pxjgApi/train/trainRecord/get',
        headers: {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
            'Accept': 'application/json, text/plain, */*',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'Cache-Control': 'no-cache',
            'Origin': 'https://pxjg-gd.i-aq.cn',
            'Pragma': 'no-cache',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-origin',
            'product-code': 'pxjgYwpt',
            'project-code': 'gdpxjg',
            'sec-ch-ua': '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sso-token': ssoToken,
            'token-version': 'V2.1',
            'Cookie': 'pageNo=1; pageSize=10'
        },
        data: data
    };

    const result = (await axios.request(config)).data
    return result
}


const main = async () => {

    const operationType = await 获取输入_plus({
        prompt: "请输入操作类型：1.课程列表 2.开课二维码 3.学生二维码",
        key: "operationType"
    })

    switch (operationType) {
        case '1':
            {
                const ssoToken = await 获取输入_plus({
                    prompt: "请输入ssoToken：",
                    key: "ssoToken"
                })
                const result = await getTrainList({ ssoToken })
                console.log(JSON.stringify(result));

            }
            break
        case '2':
            {
                const signType = await 获取输入_plus({
                    prompt: "请输入二维码类型：(老师开课二维码teacherSign)",
                    key: "signType"
                })

                const ssoToken = await 获取输入_plus({
                    prompt: "请输入ssoToken：",
                    key: "ssoToken"
                })

                const id = await 获取输入_plus({
                    prompt: "请输入课程id：",
                    key: "id"
                })

                const result = await getCourseOffersQrCode({
                    ssoToken,
                    id,
                    signType
                })

                console.log(JSON.stringify(result));
            }
            break
        case '3':
            {
                const signType = 10

                const ssoToken = await 获取输入_plus({
                    prompt: "请输入ssoToken：",
                    key: "ssoToken"
                })

                const id = await 获取输入_plus({
                    prompt: "请输入课程id：",
                    key: "id"
                })

                const result = await getCourseOffersQrCode({
                    ssoToken,
                    id,
                    signType
                })

                console.log(JSON.stringify(result));
            }
            break;
    }
}


main();